/*
 * Program finds prime numbers which are smaller or equal to the inputted
 * from keyboard integer number.
 *
 * @version  1.0 26 Jan 2013
 * @author Myhaylo Kotsyuruba (javatrainee15)
 */
 
 
import java.util.ArrayList;
import java.util.Scanner;


public class PrimeNumbers {
    public static void main (String[] args) {
        int maxNumber = getNumber();
        ArrayList<Integer> primeNumbers = findPrimeNumbers(maxNumber);
        issueArray(primeNumbers);
    }
    
    static int getNumber() {
        int number = 0;
        Scanner inputFromKeybord = new Scanner(System.in);
        System.out.print("Input number: ");
        number = inputFromKeybord.nextInt();
        return number;
    }
    
    static ArrayList<Integer> findPrimeNumbers(int maxNumber) {
        ArrayList<Integer> prime = new ArrayList<Integer>();
        int firstPrime = 2;
        for (int numberA = firstPrime; numberA <= maxNumber; numberA++) {
            boolean isSimle = true;
            int rootNumber = (int)(Math.sqrt(numberA));
            for(int divisor : prime) {
                if (divisor > rootNumber) {
                    break;
                }
                if ((numberA % divisor) == 0) {
                    isSimle = false;
                    break;
                }
            }
            if (isSimle) {
                prime.add(numberA);
            }
        }
        return prime;
    }
    
    static void issueArray(ArrayList<Integer> numbers) {
        System.out.println("Answer: " + numbers);
    }
}    